home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr51 / tag_utes.zip / REDOTAGS.PRG < prev    next >
Text File  |  1993-04-01  |  5KB  |  130 lines

  1. PROCEDURE RedoTags
  2. *-------------------------------------------------------------------------------
  3. *-- Programmer..: David Love (DAVIDLOVE)
  4. *-- Date........: 01/20/1992
  5. *-- Notes.......: This routine is a "generic" MDX cleanup routine. It is useful
  6. *--               for handling "bloated" MDX files -- ones that have been around
  7. *--               awhile (they tend to be larger than necessary). This routine
  8. *--               store the FOR/ASCENDING/UNIQUE options to a database and the
  9. *--               tag keys in an array, delete the tags, and rebuild the MDX
  10. *--               file from scratch, restoring all tag names and key expressions
  11. *--               The MDX SHOULD be smaller (one test showed one MDX to go
  12. *--               from 67,584 bytes to 59,392 bytes).
  13. *--             : This routine will only act on the database's production mdx
  14. *--               file (ie. has the same name as the dbf file).
  15. *--             : This procedure will create a database file (RedoTags.dbf) and
  16. *--               a text file (RedoTags.txt).  Upon completion, both files will
  17. *--               be erased.  These files are necessary because dBASE IV 1.1
  18. *--               does not have functions that return the FOR/DESCENDING/UNIQUE
  19. *--               options of the index tags.
  20. *-- Written for.: dBASE IV, 1.1
  21. *-- Rev. History: 01/22/1992 -- Recognizes FOR/UNIQUE/DESCENDING clauses
  22. *--               01/24/1992 -- Incorporates auto-creation of Tags.dbf
  23. *--               01/31/1991 -- Minor cleanup, removed three unneeded lines
  24. *-- Calls.......: None
  25. *-- Called by...: Any
  26. *-- Usage.......: do RedoTags with "<cDBF>"
  27. *-- Example.....: do RedoTags with "Referral"
  28. *-- Returns.....: None
  29. *-- Parameters..: cDBF = Name of DATABASE file, no extension necessary.
  30. *-- Acknowledgement..: Bowen Moursund for the code that creates RedoTags.dbf
  31. *--                    (Download PRGCREAT.ZIP for more info.)
  32. *--                  : Ken Mayer for interest and encouragement
  33. *-------------------------------------------------------------------------------
  34.  
  35.     parameter cDBF
  36.     
  37.     use (cDBF)
  38.     
  39.     *-- only perform routine if an index tag exists
  40.     if "" # tag( (cdbf), 1)
  41.       private nTags, nMaxTags, mkey, mtag, cConsole
  42.  
  43.       *-- used to find UNIQUE/DESCENDING/FOR clauses
  44.       cConsole = set("CONSOLE")
  45.       set console off
  46.       if file("RedoTags.txt")
  47.         erase "RedoTags.txt"
  48.       endif
  49.       list stat to file RedoTags.txt
  50.  
  51.       *-- creates a database file, RedoTags.dbf, which has three 254 char fields
  52.       if file("RedoTags.dbf")
  53.         erase "RedoTags.dbf"
  54.       endif
  55.       set printer to file RedoTags.dbf
  56.       set printer on
  57.       ??? "{3}{92}{1}{24}{0}{0}{0}{0}{129}{0}{251}{2}{0}{0}{0}{0}{0}{0}{0}{0}{0}"+;
  58.       "{0}{0}{0}{0}{0}{0}{0}{0}{0}{201}{0}{84}{65}{71}{83}{49}{0}{0}{0}{0}{0}{0}"+;
  59.       "{67}{3}{0}{26}{84}{254}{0}{0}{0}{1}{0}{0}{0}{0}{0}{0}{0}{0}{0}{0}{0}{84}"+;
  60.       "{65}{71}{83}{50}{0}{0}{0}{0}{0}{0}"
  61.       ??? "{67}{1}{1}{26}{84}{254}{0}{0}{0}{1}{0}{0}{0}{0}{0}{0}{0}{0}{0}{0}{0}"+;
  62.       "{84}{65}{71}{83}{51}{0}{0}{0}{0}{0}{0}{67}{255}{1}{26}{84}{254}{0}{0}{0}"+;
  63.       "{1}{0}{0}{0}{0}{0}{0}{0}{0}{0}{0}{0}{13}{26}"
  64.       set printer to
  65.       set printer off
  66.  
  67.       use RedoTags
  68.       append from RedoTags.txt type sdf for "TAG:" $ tags1
  69.       set console &cConsole
  70.  
  71.       *-- figure out how many tags there are
  72.       nMaxTags = reccount()
  73.  
  74.       *-- put any 'for' expression in a separate field
  75.       replace all tags3 with iif( at("For:",tags1) > 0, ;
  76.         substr( tags1, at("For:",tags1) + 5) + " " + trim(tags2),"")
  77.  
  78.       *-- declare an array to hold the info
  79.       declare aTags[nMaxTags,5]
  80.  
  81.       *-- store descending/unique/for info to the array variables
  82.       go top
  83.       nTags = 1
  84.       do while .not. eof()
  85.         store "(Descending)" $ tags1 to aTags[nTags,3]
  86.         store "(Unique)" $ tags1 to aTags[nTags,4]
  87.         store trim( tags3 ) to aTags[nTags,5]
  88.         nTags = nTags + 1
  89.         skip
  90.       enddo
  91.  
  92.       *-- store the key expressions and tags to the array
  93.       use (cDBF)
  94.       nTags = 1
  95.       do while "" # tag( (cDBF),nTags )
  96.         store key( (cDBF),nTags ) to aTags[nTags,1]  && grab the key
  97.         store tag( (cDBF),nTags ) to aTags[nTags,2]  && grab the tagname
  98.         nTags = nTags + 1
  99.       enddo
  100.  
  101.       *-- now, delete the tags   
  102.       do while "" # tag( (cDBF),1 )
  103.         delete tag tag( (cDBF),1 )
  104.       enddo
  105.       
  106.       *-- rebuild the MDX, tag by tag ...
  107.       nTags = 1
  108.       do while nTags <= nMaxTags
  109.         mkey = aTags[nTags,1] + ;
  110.         iif(aTags[nTags,3]," descending","") + ;
  111.           iif(aTags[nTags,4]," unique","") + ;
  112.           iif(""#trim(aTags[nTags,5])," for "+trim(aTags[nTags,5]),"")
  113.         mtag = aTags[nTags,2]
  114.         index on &mkey. TAG &mtag.
  115.         nTags = nTags + 1
  116.       enddo
  117.     
  118.       *-- delete the dbf and text files
  119.       erase "RedoTags.dbf"
  120.       erase "RedoTags.txt"
  121.  
  122.       *-- release the array ...
  123.       release aTags
  124.     
  125.     endif  && check for tags ...
  126.     use  && close database
  127.     
  128. RETURN
  129. *-- EoP: RedoTags
  130.